﻿// (c)2010 David Schwarz (david.schwarz@live.com)
// This file is licensed under GNU GPL v2 license, see more at http://www.gnu.org/licenses/gpl-2.0.html
namespace vKapse.DDTool.Core
{

	#region Using

	using System;
	using System.Collections.Generic;
	using System.Text;
using System.Windows.Forms;

	#endregion Using

	/// <summary>
	/// Sekce trigerů
	/// </summary>
	public class TriggerGroup
	{

		#region Members

		private string m_text;
		private int m_position;
		private List<TriggerBase> m_triggers;
		private List<TriggerGroup> m_groups;

		#endregion Members

		#region Constructor

		/// <summary>
		/// Konstruktor
		/// </summary>
		/// <param name="text">Název sekce</param>
		public TriggerGroup(string text)
			: this(text, 0)
		{
		}

		public TriggerGroup(string text, int position)
		{
			this.m_text = text;
			this.m_position = position;
			this.m_triggers = new List<TriggerBase>();
			this.m_groups = new List<TriggerGroup>();
		}

		#endregion Constructor

		public int Position
		{
			get
			{
				return this.m_position;
			}
			set
			{
				this.m_position = value;
			}
		}

		public string Text
		{
			get
			{
				return this.m_text;
			}
		}

		#region Methods

		public void AddTrigger(TriggerBase trigger)
		{
			if (trigger == null)
			{
				return;
			}
			this.m_triggers.Add(trigger);
		}

		public ToolStrip CreateToolStrip()
		{
			ToolStrip toolStrip = new ToolStrip();
			toolStrip.Text = this.m_text;
			foreach (TriggerBase trigger in this.m_triggers)
			{
				if (!trigger.ToToolBar)
				{
					continue;
				}
				ToolStripItem item = null;
				if (trigger is SeparatorTrigger)
				{
					continue;
					//item = new ToolStripSeparator();
				}
				else
				{
					if (trigger.IsComboBox)
					{
						item = new ToolStripComboBox();
						((ToolStripComboBox)item).Items.AddRange(trigger.List.ToArray());
						((ToolStripComboBox)item).DropDownStyle = ComboBoxStyle.DropDownList;
					}
					else
					{
						item = new ToolStripButton();
					}
					item.DisplayStyle = ToolStripItemDisplayStyle.Image;
					trigger.Associate(item);
				}
				toolStrip.Items.Add(item);
			}
			return toolStrip;
		}


		public ToolStripItem[] CreateMenu()
		{
			List<ToolStripItem> main = new List<ToolStripItem>();
			foreach (TriggerBase trigger in this.m_triggers)
			{
				if (trigger is SeparatorTrigger)
				{
					main.Add(new ToolStripSeparator());
					continue;
				}
				if (trigger.IsComboBox)
					continue;
				ToolStripMenuItem menuItem = new ToolStripMenuItem();
				trigger.Associate(menuItem);
				main.Add(menuItem);
			}
			return main.ToArray();
		}

		#endregion Methods
	}
}
